package com.myapplication.ui.showfragment;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.myapplication.R;
import com.myapplication.bean.ShaiwuBean;
import com.myapplication.utils.CropCircleTransformation;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by My on 2016/10/5.
 */
public class ShaiWuFragmentAdapter extends BaseAdapter {
    private List<ShaiwuBean.DataBean.ListBean> shaiwwulist;
    private Context context;

    public void setShaiwuList(List<ShaiwuBean.DataBean.ListBean> shaiwwulist) {
        this.shaiwwulist = shaiwwulist;
    }

    public void setHolder(ViewHolder holder) {
        this.holder = holder;
    }

    public void setContext(Context context) {
        this.context = context;
    }

    public ShaiWuFragmentAdapter(Context context, List<ShaiwuBean.DataBean.ListBean> shaiwwulist){
        this.context=context;
        this.shaiwwulist=shaiwwulist;
    }

    @Override
    public int getCount() {
        return shaiwwulist.size();
    }

    @Override
    public Object getItem(int i) {
        return shaiwwulist.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    ViewHolder holder;
    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        holder=new ViewHolder();
        if(view==null){
            view= LayoutInflater.from(context).inflate(R.layout.item_lv_show,null);
            holder.iv_shaiwu_big= (ImageView) view.findViewById(R.id.iv_shaiwu_big);
            holder.iv_shaiwu_small= (ImageView) view.findViewById(R.id.iv_shaiwu_small);
            holder.tv_shaiwu_nickname= (TextView) view.findViewById(R.id.tv_shaiwu_nickname);
            holder.tv_shaiwu_title= (TextView) view.findViewById(R.id.tv_shaiwu_title);
            holder.tv_shaiwu_subTitle= (TextView) view.findViewById(R.id.tv_shaiwu_subTitle);
            view.setTag(holder);
        }else{
            holder= (ViewHolder) view.getTag();
        }
        holder.tv_shaiwu_nickname.setText(shaiwwulist.get(i).getShaidan().getEditor().getNickname());
        holder.tv_shaiwu_title.setText(shaiwwulist.get(i).getShaidan().getTitle());
        holder.tv_shaiwu_subTitle.setText(shaiwwulist.get(i).getShaidan().getSubTitle());
        Picasso.with(context)
                .load(shaiwwulist.get(i).getShaidan().getImageUrl())
                .into(holder.iv_shaiwu_big);
        Picasso.with(context)
                .load(shaiwwulist.get(i).getShaidan().getEditor().getAvatar())
                .transform(new CropCircleTransformation())
                .into(holder.iv_shaiwu_small);
        return view;
    }
    static class ViewHolder{
        ImageView iv_shaiwu_big,iv_shaiwu_small;
        TextView tv_shaiwu_nickname,tv_shaiwu_title,tv_shaiwu_subTitle;
    }
}
